package com.amigo.online.provider.common.compare.impl;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.amigo.online.provider.common.compare.AbstractBasicCompareService;
import com.amigo.online.provider.common.compare.BasicCompareService;
import com.amigo.online.provider.common.entity.VideoMysqlInfo;
import com.amigo.online.provider.common.entity.VideoSolrInfo;


public class VideoSolrCompareServiceImpl implements BasicCompareService<VideoMysqlInfo, VideoSolrInfo, Long> {

    @Override
    public Long compare(VideoMysqlInfo source, VideoSolrInfo target) {
        Class<?> targetClass = target.getClass();
        Class<?> sourceClass = source.getClass();
        Field[] targetFields = targetClass.getDeclaredFields();
        Field[] sourceFields = sourceClass.getDeclaredFields();
        Map<String, Object> resultMap = new HashMap<>();
        for (int i = 0; i < targetFields.length; i++) {
            targetFields[i].setAccessible(true);
            for (int j = 0; j < sourceFields.length; j++) {
                if (targetFields[i].getName().equals(sourceFields[j].getName())) {
                    sourceFields[j].setAccessible(true);
                    try {
                        if (!AbstractBasicCompareService.compareTwo(targetFields[i].get(target), sourceFields[j].get(source))) {
                            resultMap.put(sourceFields[j].getName(), sourceFields[j].get(source));
                        }
                    } catch (IllegalArgumentException | IllegalAccessException e) {
                        e.printStackTrace();
                    }
                    break;
                }

            }
        }
        return null;
    }

}
